#ifndef _COMMON_H_
#define _COMMON_H_

#define CAN_CMD_LENGTH 		28		//4*5 + 8(0~8) 

typedef	signed char 		int8_t;
typedef	signed short int 	int16_t;
typedef	signed int 			int32_t;

typedef	unsigned char 		uint8_t;
typedef unsigned short int 	uint16_t;
typedef unsigned int 		uint32_t;


/* cmd union data16*/
typedef union
{
	int8_t	raw[2];
	int16_t data16;
}DATA16_t;

/* data union data32*/
typedef union
{
	uint8_t	raw[4];
	uint32_t data32;
}DATA32_t;


// CAN sendcmd struct
typedef union
{
	uint8_t	CANTxMsg[CAN_CMD_LENGTH];
	struct
	{
		uint32_t  StdId;
		uint32_t	ExtId;
		uint32_t	IDE;
		uint32_t	RTR;
		uint32_t	DLC;
		uint8_t		Data[8];
	}CANTxStruct;
}CANTxMsg_t;


/**********************电机控制相关************/
//控制模式
typedef enum
{
	NOMODEADOPT = 0x00,		//无模式
	PROFILEVELOCITYMODE = 0x01,
	PROFILEPOSITIONMODE = 0x02,
	HOMINGMODE	= 0x03,
}MOTORCTRLMODE_t;

typedef enum
{
	CLOSED = 0x00,	//断开
	OPENED = 0x01,	//闭合
}STATUS_t;


//驱动器通道号
typedef enum
{
	NOCHANNEL		= 0x00,  //不区分通道号
	CHANNEL1 = 0x01,			//科亚的驱动器需要通道号
	CHANNEL2 = 0x02,
	
}DRIVECHANNEL_t;


/*****************协议解析相关****************/
//上位机指令操作类型：operate
typedef enum{
	//设备类型：
	ALL_DEVICES = 0x01,				    //所有设备
	THE_INFO = 0x02, 					//机器人信息上报
	ROBOT_LINEWALKING = 0x03,	        //机器人巡线功能开启
	ROBOT_ACTION = 0x04,				//小车动作控制
	NVIDIA_BACK  = 0x05,  		        //NVIDIA回传数据
    ROBOT_ODOM = 0x06,	                //NVIDIA返回机器人里程数据 
	ROBOT_CHARGE = 0x11,			    //一键充电
	TING_KAO = 0x12,					//上位机给出停靠点信息
	AUTO_AROUND = 0x13,				    //一键自动巡检
	TEST_CMD = 0x14,				    //测试使用
	TIME_STATE = 0x15,					//时间状态，白天还是晚上
	CUR_POSSET = 0x16, 				    //设置当前位置
}ENUM_OPERATE;


//对电机的操作选项：devicetype
typedef enum{
	MOTORINIT = 0x01,	//初始化---boot,ctrlmode set,other thing set
	MOTORSTATUS = 0x02, //使能控制---enable,disable
	MOTORSERVOANGLE = 0x03,  //关节角度设置,读取
	MOTORVELOCITY = 0x04,  //速度设定，读取
	MOTORSTOP	= 0x05,   //控制停止----普通停止，急停
	MOTORRUN = 0x06,  //RUN---启动运转指令
	MOTORSETCTRLMODE = 0x07, //设置模式
	MOTORCURRENT = 0x08,  //电机电流
	MOTORERRCODE = 0x09,  //错误代码
}ENUM_DEVICETYPE;

//机器人动作 -> ROBOTACTION
typedef enum
{
  STOP = 0,
  FORWARD = 0x01,     //前进
  BACKWARD = 0x02,     //向后
  TURNRIGHT = 0x03,   //原地右转
  TURNLEFT = 0x04,     //原地左转
}ACTION_TYPE;


//通信接口文件描述符
typedef enum
{
	CANFD = 0x00,		//CAN
	ETHFD,
	CLIENTFD,
	UARTFD,
    UDPFD,
	MAXFD,			//文件描述符数量
}HANDLEFD;


#define UART_QUEUE_LENGTH   20      //队列长度
#define UART_CMD_LENGTH     4       //命令长度

#define ETH_QUEUE_LENGTH    20      
#define ETH_CMD_LENGTH      8

#define UDP_QUEUE_LENGTH    20
#define UDP_CMD_LENGTH      8





#endif // !_COMMON_H_
